page.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use client";
  2. import { getLoginApi, getUserInfoApi } from "@/api/user";
  3. import { useRouter } from "@/i18n";
  4. import { useGlobalStore } from "@/stores";
  5. import { Toast } from "antd-mobile";
  6. import { useTranslations } from "next-intl";
  7. import { useSearchParams } from "next/navigation";
  8. import dynamic from "next/dynamic";
  9. import { FC, useState } from "react";
  10. import "./page.scss";
  11. interface Props {}
  12. const HeaderBack = dynamic(() => import('@/components/HeaderBack'));
  13. const FromCom = dynamic(() => import('./component/FromCom'));
  14. const GoogleCom = dynamic(() => import('./component/GoogleCom'));
  15. const DomainFooter = dynamic(() => import('@/components/DomainFooter'));
  16. const Login: FC<Props> = () => {
  17. const t = useTranslations("LoginPage");
  18. const { setToken, setUserInfo } = useGlobalStore();
  19. const router: any = useRouter();
  20. let searchParams = useSearchParams();
  21. let redirect = searchParams.get("redirect") || "";
  22. const [msgError, setMsgError] = useState("");
  23. const loginRequest = async ({ userPhone, pwd }: any) => {
  24. let params = { user_phone: userPhone, pwd };
  25. let res = await getLoginApi(params);
  26. if (res.code == 200) {
  27. setToken(res.data.token);
  28. Toast.show({
  29. icon: "loading",
  30. content: "请求中...",
  31. duration: 10000,
  32. maskClickable: false,
  33. });
  34. getUserInfoApi().then((res1) => {
  35. if (res1.code == 200) {
  36. Toast.show({ icon: "success", content: t("loginSuc"), maskClickable: false });
  37. setUserInfo(res1.data);
  38. setTimeout(() => {
  39. router.replace("/" + redirect);
  40. }, 1000);
  41. }
  42. });
  43. }
  44. setMsgError(res.msg || "");
  45. };
  46. return (
  47. <div className="login-box">
  48. <HeaderBack showBack={false}/>
  49. <div className="content-box">
  50. <GoogleCom />
  51. <FromCom callbackFun={loginRequest} msgError={msgError} />
  52. <DomainFooter />
  53. </div>
  54. </div>
  55. );
  56. };
  57. export default Login;